<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>返回元素第n个兄弟元素节点</title>
</head>
<body>
    <div>
        <a href=""></a>
        <span></span>
        <p></p>
        <strong></strong>
        dsasd
        <!-- dxascads -->
        <p></p>
        <i></i>
    </div>
</body>
<script>
    function retSibling(elem, n) {
        while(elem && n) {
            if (n > 0) {
                if (elem.nextElementSibling) {
                    elem = elem.nextElementSibling;
                }else{
                    for (elem = elem.nextSibling; elem && elem.nodeType != 1; elem = elem.nextSibling) ;
                }
                n--;
            }else{
                if (elem.previousElementSibling) {
                    elem = elem.previousElementSibling;
                }else{
                    for (elem = elem.previousSibling; elem && elem.nodeType != 1; elem = elem.previousSibling) ;
                }
                n++;
            }
        }
        return elem;
    }
    var span = document.getElementsByTagName('span')[0];
</script>
</html>
